#include <iostream>
#include <vector>
#include <fstream>
#include <cmath>

using namespace std;

int getExp(int N) {
    int lN = 1;
    while (lN < N) {
        lN <<= 1;
    }
	return lN;
}

int getGCD(int l, int r) {
    if (l == 0 || l == r || l == -1) 
        return (r == 0) ? -1 : r;
    if (r == 0 || r == -1) 
        return l;
    if (r == 1 || l == 1)
        return 1;
    if (l > r)
        return getGCD(l - (int)(l / r) * r, r);
    else
        return getGCD(l, r - (int)(r / l) * l);
}

void buildSegmentTree(vector<int>& a, vector<int>& answ) {
    vector<int> tmp(a);
    int n = getExp(a.size());
    tmp.resize(n, -1);
    for (size_t i = 0; 2 * i + 1 < tmp.size(); ++i) {
        tmp.push_back(getGCD(tmp[2 * i], tmp[2 * i + 1]));
    }
    size_t k = tmp.size();
    answ.push_back(-1);
    answ.push_back(tmp[0]);
    for (size_t i = 1; i < k; i = (i << 1) + 1){
        int iEnd = (i << 1) + 1;
        for (size_t j = 0; j <= i && j < k; ++j)
            answ.push_back(tmp[k - iEnd + j]);
    }
}

int getAnswer(vector<int>& tree, int length, int start, int end, int l, int r) {

	if (start == l && end == r) {
		return tree[length];
	}
	int middle = (start + end) / 2;
	if (start <= l && r <= middle) { 
		return getAnswer(tree, 2 * length, start, middle, l, r);
	}
	if (middle + 1 <= l && r <= end) {
		return getAnswer(tree, 2 * length + 1, middle + 1, end, l, r);
	}
	int leftGCD = getAnswer(tree, 2 * length, start, middle, l, middle);
	int rightGCD = getAnswer(tree, 2 * length + 1, middle + 1, end, middle + 1, r);
	return getGCD(leftGCD, rightGCD);
}

int main() {    
    ifstream ifile("in.txt");
    int N;
    ifile >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i)  
        ifile >> a[i];
    vector<int> tree;
    buildSegmentTree(a, tree);
    int M, i, j;
    ifile >> M;
    for (int l = 0; l < M; ++l)
    {
        ifile >> i >> j;
        cout << getAnswer(tree, 1, 0, N-1, i, j) << endl;
    }
    ifile.close();
    return 0;
}